package com.moonfish.base.controller.Response;

import com.moonfish.base.model.menu.Menu;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mayu on 2017/7/27.
 * email:showmara@qq.com
 */
@Data
public class MenuResponseBody extends BaseResponseBody {
    public MenuResponseBody(ErrCode status, String message, String path, List<Router> body) {
        super(status, message, path, body);
        this.body = body;
    }
    private List<Router> body;
    @Data
    public static class Router {
        private String id;
        private String pid;
        private String name;
        private String path;
        private Meta meta;
        private String component;
        private int level;
        private List<Router> children = new ArrayList<>();
    }

    @Data
    public static class Meta {
        private String icon;
        private boolean expanded;
        private String link;
        private String label;
        private String description;
        private String repository;
    }

    public static List<Router> makeRouter(List<Menu> menus) {
        List<Router> routers = new ArrayList<>();
        for (int i = 0; i < menus.size(); i++) {
            Menu menu = menus.get(i);
            Router router = new Router();
            router.setLevel(menu.getLevel());
            router.setId(menu.getId());
            router.setPid(menu.getPid());
            router.setName( menu.getName());
            router.setPath( menu.getPath());
            Meta meta = new Meta();
            meta.setDescription( menu.getDescription());
            meta.setExpanded(menu.isExpanded());
            meta.setIcon(menu.getIcon());
            meta.setLabel(menu.getLabel());
            meta.setLink(menu.getLink());
            meta.setRepository(menu.getRepository());
            router.setMeta(meta);
            routers.add(router);
        }
        return routers;
    }
}
